package com.example.permissionsystem1_1.businessFunction.service.converter;

import com.example.permissionsystem1_1.businessFunction.dao.entity.po.DepartmentUserPo;
import com.example.permissionsystem1_1.businessFunction.dao.entity.po.UserRolePo;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.departmentUserReqModel.DepartmentUserSelectAllDepartmentsByUserIdReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.departmentUserReqModel.DepartmentUserSetDepartmentUserRelationReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.userRoleReqModel.UserRoleSelectAllRolesByUserIdReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.userRoleReqModel.UserRoleSetUserRoleRelationReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.departmentUserRspModel.DepartmentUserRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.departmentUserRspModel.DepartmentUserSelectAllDepartmentsByUserIdRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.departmentUserRspModel.DepartmentUserSetDepartmentUserRelationRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.userRoleRspModel.UserRoleRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.userRoleRspModel.UserRoleSelectAllRolesByUserIdRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.userRoleRspModel.UserRoleSetUserRoleRelationRspModel;
import com.example.permissionsystem1_1.common.businessFunction.BaseServiceConverter;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class UserRoleServiceConverter extends BaseServiceConverter {
    //1.selectAllRolesByUserId
    public static UserRolePo convertReqModelToPo(UserRoleSelectAllRolesByUserIdReqModel reqModel) {
        if (reqModel == null || reqModel.getUserId()==null) {
            return null;
        }
        UserRolePo po=new UserRolePo();
        BeanUtils.copyProperties(reqModel, po);
        return po;
    }
    public static UserRoleSelectAllRolesByUserIdRspModel covertToSelectAllRolesByUserIdModel(List<UserRolePo> pos) {
        if( pos == null) {
            return null;
        }
        UserRoleSelectAllRolesByUserIdRspModel rspModel=new UserRoleSelectAllRolesByUserIdRspModel();
        if(pos.size()>0){
            List<UserRoleRspModel> userRoleRspModels=new ArrayList<>();
            for (UserRolePo po:pos) {
                UserRoleRspModel userRoleRspModel=new UserRoleRspModel();
                BeanUtils.copyProperties(po, userRoleRspModel);
                userRoleRspModels.add(userRoleRspModel);
            }
            rspModel.setUserRoleRspModels(userRoleRspModels);
        }
        return rspModel;
    }
    //2.setUserRoleRelation
    public static List<UserRolePo> convertReqModelToPo(UserRoleSetUserRoleRelationReqModel reqModel) {
        if (reqModel == null || reqModel.getUserId()==null || reqModel.getRoleIds()==null || reqModel.getRoleIds().size()<=0) {
            return null;
        }
        List<Long> roleIds=reqModel.getRoleIds();
        List<UserRolePo> userRolePos=new ArrayList<>();
        for (Long roleId:roleIds) {
            UserRolePo userRolePo=new UserRolePo();
            userRolePo.setUserId(reqModel.getUserId());
            userRolePo.setRoleId(roleId);
            setDefaultAttributesValue(userRolePo);
            userRolePos.add(userRolePo);
        }
        return userRolePos;
    }
    public static UserRoleSetUserRoleRelationRspModel covertToSetUserRoleRelationModel(Integer i) {
        UserRoleSetUserRoleRelationRspModel rspModel=new UserRoleSetUserRoleRelationRspModel();
        rspModel.setResultSum(i);
        return rspModel;
    }




}
